package IT09;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/*
ArrayList嵌套HashMap
 */
public class ArrayListIncludeHashMapDemo {
    public static void main(String[] args) {
        ArrayList<HashMap<String,String>> array = new ArrayList<>();
        //把HashMap作为元素添加到ArrayList集合
        HashMap<String,String> hm1 = new HashMap<>();
        hm1.put("孙策","大乔");
        hm1.put("周瑜","小乔");
        array.add(hm1);
        HashMap<String,String> hm2 = new HashMap<>();
        hm1.put("郭靖","黄蓉");
        hm1.put("杨过","小龙女");
        array.add(hm2);
        HashMap<String,String> hm3 = new HashMap<>();
        hm1.put("令狐冲","任盈盈");
        hm1.put("林平之","岳灵珊");
        array.add(hm3);
        //遍历ArrayList集合
        for(HashMap<String,String> hm:array){
            Set<String> keySet = hm.keySet();
            for(String key : keySet){
                String value = hm.get(key);
                System.out.println(key + "," + value);
            }
        }
    }
}
